<template>
<div>
  <h1 style="color: #6AAB9C">欢迎{{admin.username}}管理员进入后台！</h1>
<!--  <el-card class="box-card" style="width: 500px; height: 400px">-->

<!--  </el-card> -->
  <el-row :span="10" style="margin-bottom: 20px">
    <el-col :span="6">
      <el-card>
        <div style="color: #6AAB9C">用户总数</div>
        <div style="padding: 10px 0; text-align: center; font-weight: bold">
          {{ userCount }}
        </div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card>
      <div style="color: #F56C6C">医生总数</div>
      <div style="padding: 10px 0; text-align: center; font-weight: bold">
        {{ phyCount }}
      </div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card>
      <div style="color: #E6A23C">医院总量</div>
      <div style="padding: 10px 0; text-align: center; font-weight: bold">
        {{ hosCount }}
      </div>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card>
      <div style="color: #409EFF">订单总量</div>
      <div style="padding: 10px 0; text-align: center; font-weight: bold">
        {{ orderCount }}
      </div>
      </el-card>
    </el-col>
  </el-row>
  <el-row>
    <el-col :span="12">
      <el-card style="width: 500px; height: 400px">
        <div id="main" style="width: 500px; height: 400px"></div>
      </el-card>
    </el-col>
    <el-col :span="12">
      <el-card style="width: 500px; height: 400px">
        <div id="pie" style="width: 500px; height: 400px"></div>
      </el-card>
    </el-col>
  </el-row>

</div>
</template>

<script>
 import * as echarts from 'echarts'

export default {
  name: "Home",
  data() {
    return {
      admin: localStorage.getItem("adminInfo") ? JSON.parse(localStorage.getItem("adminInfo")) : {},
      userCount: 0,
      phyCount: 0,
      hosCount: 0,
      orderCount: 0,
    }
  },
  created() {
    console.log(this.$router)
    this.request.get("/user/count").then(res => {
      this.userCount = res
    })
    this.request.get("/physician/count").then(res => {
      this.phyCount = res
    })
    this.request.get("/hospital/count").then(res => {
      this.hosCount = res
    })
    this.request.get("/order/count").then(res => {
      this.orderCount = res
    })
  },
  mounted() { //页面元素渲染之后再触发
    var option = {
      title: {
        text: '各季度用户数量统计',
        subtext: '趋势图',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        }
      ]
    };
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    /*this.request.get("/echarts/members").then(res => {
      //option.xAxis.data = res
      option.series[0].data = res
      option.series[1].data = res
      myChart.setOption(option);
    })*/


    //饼图
    var pieOption = {
      title: {
        text: '各季度订单数量统计',
        subtext: '饼图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '50%',
          label:{            //饼图图形上的文本标签
            normal:{
              show:true,
              position:'inner', //标签的位置
              textStyle : {
                fontWeight : 300 ,
                fontSize : 14,    //文字的字体大小
                color: "#fff"
              },
              formatter:'{d}%'
            }
          },
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);

    this.request.get("/echarts/members").then(res => {
      //option.xAxis.data = res
      option.series[0].data = res
      option.series[1].data = res
      myChart.setOption(option);

      /*pieOption.series[0].data = [
        {name: "第一季度", value: res[0]},
        {name: "第二季度", value: res[1]},
        {name: "第三季度", value: res[2]},
        {name: "第四季度", value: res[3]},
      ]
      pieChart.setOption(pieOption);*/
    })

    this.request.get("/echarts/orders").then(res => {
      //option.xAxis.data = res
      pieOption.series[0].data = [
        {name: "第一季度", value: res[0]},
        {name: "第二季度", value: res[1]},
        {name: "第三季度", value: res[2]},
        {name: "第四季度", value: res[3]},
      ]
      pieChart.setOption(pieOption);
    })


  }
}
</script>

<style scoped>

</style>
